package com.sunyy.codegenerator.service.impl;


import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.sunyy.codegenerator.common.MyException;
import com.sunyy.codegenerator.dto.groupVariable.SaveGroupVariableDto;
import com.sunyy.codegenerator.entity.GroupVariable;
import com.sunyy.codegenerator.mapper.GroupVariableMapper;
import com.sunyy.codegenerator.service.GroupVariableService;
import com.sunyy.codegenerator.util.SnowflakeUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 60382
 * @description 针对表【group_variable(模板组合的变量)】的数据库操作Service实现
 * @createDate 2025-07-19 10:58:18
 */
@Service
@Transactional
public class GroupVariableServiceImpl extends ServiceImpl<GroupVariableMapper, GroupVariable>
        implements GroupVariableService {

    @Override
    public void saveGroupVariable(SaveGroupVariableDto dto) {
        // 1. 通用参数鉴权
        if (dto == null) {
            throw new MyException("入参不能为空!!");
        }
        boolean isNewOne = dto.getPkid() == null || dto.getPkid() < 0;
        if (isNewOne) {
            // 新增
            if (dto.getGroupId() == null || dto.getGroupId() < 0) {
                throw new MyException("入参【groupId】非法!!");
            }
            if (StringUtils.isBlank(dto.getVariableName())) {
                throw new MyException("入参【variableName】不能为空!!");
            }
            dto.setPkid(SnowflakeUtil.getId());
        } else {
            // 修改
        }
        GroupVariable entity = new GroupVariable();
        BeanUtils.copyProperties(dto, entity);
        if (isNewOne) {
            save(entity);
        } else {
            updateById(entity);
        }
    }
}




